<?php
/**
 * Created by PhpStorm.
 * User: 王峥宇
 * Date: 2019-04-28
 * Time: 9:40
 */

namespace app\admin\model;
use think\Session;

class Balancelog extends BaseModel
{
 
   public function balancelogindex()
    {
        //获取当前登陆的id
        $uid = Session::get('admin_uid');
        $vip = Guanli::where('id',$uid)->find();
        $arr = User::where('uid',$vip['uid'])->find();
        $rs = self::alias('ls')
            ->join('jc_user us','us.uid=ls.uid')
            ->order('ls.id desc')
            ->paginate(5);
    	$where=[];
        if($arr['daili']==1)
        {
            $rs = self::alias('ls')
                ->join('jc_user us','us.uid=ls.uid','left')
                ->where('us.u_path','like','%,'.$arr['uid'].',%')
                ->order('ls.createtime desc')
                ->paginate(5);
            if (input('sub')) {
              $type = input('type');
              $fromtype = input('formtype');
              $datemin = input('datemin', '');//最小时间
              $datemax = input('datemax', '');//最大的吧
              if (isset($datemin) && $datemin != '') {
                  $where['createtime'] = ['>=', $datemin . ' 00:00:00'];
              }
              if (isset($datemax) && $datemax != '') {
                  $where['createime'] = ['<=', $datemax . ' 23:59:59'];
              }
              if ($type != '') {
                  $where['type'] = [
                      'like',
                      '%' . $type . '%'
                  ];
              }
              if ($fromtype != '') {
                  $where['from_type'] = [
                      'like',
                      '%' . $fromtype . '%'
                  ];
              }
               $rs =  self::alias('ls')
                ->join('jc_user us','us.uid=ls.uid','left')
                ->where('us.u_path','like','%,'.$arr['uid'].',%')
                 ->where($where)
                ->order('ls.createtime desc')->paginate(4);   
             return $rs;
        	}else{
            return $rs;
        }
        }
        if (input('sub')) {
            $type = input('type');
            $fromtype = input('formtype');
            $datemin = input('datemin', '');//最小时间
            $datemax = input('datemax', '');//最大的吧
            if (isset($datemin) && $datemin != '') {
                $where['createtime'] = ['>=', $datemin . ' 00:00:00'];
            }
            if (isset($datemax) && $datemax != '') {
                $where['createime'] = ['<=', $datemax . ' 23:59:59'];
            }
            if ($type != '') {
                $where['type'] = [
                    'like',
                    '%' . $type . '%'
                ];
            }
            if ($fromtype != '') {
                $where['from_type'] = [
                    'like',
                    '%' . $fromtype . '%'
                ];
            }
             return $rs=$rs->where($where)->paginate(7);
        }
            return $rs;
    }
}